var BaseIndex = app.controller('BaseIndex', function($rootScope, $scope, $http,$state,BaseIndexData,BaseIndexDefault) {
	try{
		$rootScope.showf=true;
		$rootScope.title = 'i创无忧';
		$rootScope.tab = 1;
		$scope.fcate=[];
		$scope.consult=[];

		$scope.currentPage = 1;
		$scope.limit = 2;
		$scope.pages = 1;
		$scope.slides=[];

		$scope.show=false;
		$scope.busy1=true;
		$scope.busy2=true;
		$scope.busy3=true;

		bannner_height("main_visual",19/36);
		var url = SITE_URL + "index.php?app=userapp&act=ad2&callback=JSON_CALLBACK";
		$http.jsonp(url).success(function (data) {
			if (data.retval.length > 0) {
				$scope.slides = data.retval;

				setTimeout(function () {
					$dragBln = false;
					$(".main_image").touchSlider({
						flexible : true,
						speed : 200,
						paging : $(".flicking_con a"),
						counter : function (e){
							$(".flicking_con a").removeClass("on").eq(e.current-1).addClass("on");
						}
					});
					$(".main_image").bind("mousedown", function() {
						$dragBln = false;
					});
					$(".main_image").bind("dragstart", function() {
						$dragBln = true;
					});
					$(".main_image a").click(function(){
						if($dragBln) {
							return false;
						}
					});
					timer = setInterval(function(){
						$("#btn_next").click();
					}, 5000);
					$(".main_visual").hover(function(){
						clearInterval(timer);
					},function(){
						timer = setInterval(function(){
							$("#btn_next").click();
						},5000);
					});
					$(".main_image").bind("touchstart",function(){
						clearInterval(timer);
					}).bind("touchend", function(){
						timer = setInterval(function(){
							$("#btn_next").click();
						}, 5000);
					});
				}, 500);
			}
			$scope.busy1=false;
		}).error(function(){
			$scope.busy1=false;
		});

		$scope.user={};
		var url=SITE_URL+"index.php?app=baseloginapp&callback=JSON_CALLBACK&act=userinfo";
		$http.jsonp(url).success(function(data) {
			if(data.done){
				$scope.user=data.retval;

				if($scope.user.company_step==""||$scope.user.company_step==null||$scope.user.company_step==undefined){
					$rootScope.go("stage");
					return;
				}
				$rootScope.title=$scope.user.company_step;

				var url=SITE_URL+"index.php?app=baseloginapp&callback=JSON_CALLBACK&act=fcategoryfirst&step="+$scope.user.company_step;
				$http.jsonp(url).success(function(data) {
					$scope.fcate=data.retval;
					$scope.busy2=false;
				}).error(function(){
					$scope.busy2=false;
				});

				var url=SITE_URL+"index.php?app=baseloginapp&callback=JSON_CALLBACK&act=indexconsult&step="+$scope.user.company_step;
				$http.jsonp(url).success(function(data) {
					if(data.done){
						$scope.consult=data.retval.data;
						$scope.pages = Math.ceil(data.retval.total
								/ $scope.limit);
						if($scope.consult!=undefined&&$scope.consult!=null&&$scope.consult!=""&&$scope.consult.length>0){
							$scope.show=true;	
						}
					}
					$scope.busy3=false;

				}).error(function(){
					$scope.busy3=false;
				});
			}
		});


		//加载更多
		$scope.loadMore = function() {
			if ($scope.currentPage < $scope.pages) {
				if ($scope.busy) {
					return false;
				}
				$scope.busy = true;
				$scope.currentPage++;
				var url = SITE_URL
				+ "index.php?app=baseloginapp&act=indexconsult&callback=JSON_CALLBACK"+"&page="+$scope.currentPage+"&step="+$scope.user.company_step;
				$http.jsonp(url).success(
						function(data) {
							if (data.done) {
								for ( var i in data.retval.data) {
									if (typeof data.retval.data[i] != "function")
										$scope.consult.push(data.retval.data[i]);
								}
								$scope.pages = Math.ceil(data.retval.total
										/ $scope.limit);
								$scope.busy = false;
								if ($scope.pages <= $scope.currentPage) {
									$scope.show=false;
									$scope.alerts = [ {
										type : 'success',
										msg : '没有更多内容了'
									} ]
								}
							}
						});
			}else{
				if ($scope.pages <= $scope.currentPage) {
					$scope.show=false;
					$scope.alerts = [ {
						type : 'success',
						msg : '没有更多内容了'
					} ]
				}
			}
		};
	}
	catch (e) {
		showcatch(e);
	}
});

BaseIndex.BaseIndexDefault = function ($q,$http,$rootScope) {
	var def = $q.defer();
	var d = [];

	var url = SITE_URL + "index.php?app=baseloginapp&act=tutorbase&callback=JSON_CALLBACK";
	$http.jsonp(url).success(function (data) {
		if (data.done&&data.retval==true) {
			$rootScope.istutor=true;
		}
		def.resolve(d);
	}).error(function(){
		def.resolve(d);
	});

	return def.promise;
}

BaseIndex.BaseIndexData=function($q, $http,$stateParams,$rootScope,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
			def.resolve('');
		}else{
			def.resolve('');
		}
		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}


app.controller('NetworkCtrl', function($routeParams, $http, $scope, $rootScope) {
	$rootScope.tab = 1;
	$scope.curpath = $rootScope.curpath;
});